# -*- coding: utf-8 -*-
import pymongo
client = pymongo.MongoClient("47.74.21.140",socketKeepAlive=True,maxPoolSize=400)
client.admin.authenticate("admin321", "dsf::6666,,<<", mechanism='SCRAM-SHA-1')
db = client.dmm
cate = set()
tag = set()
play = set()
nplay = set()
director = set()
manufacturer = set()
series = set()
import ipdb;ipdb.set_trace()
director = db.movie.distinct("director")
series = db.movie.distinct("series")
manufacturer = db.movie.distinct("manufacturer")
tag = db.movie.distinct("tag")
cate = db.movie.distinct("cate")
# result = db.movie.find()
# while 1:
#     try:
#         y = result.next()
#     except StopIteration:
#         break
#     print y.get("url")
#     tag.add(y.get("tag"))
#     series.add(y.get("series"))
#     manufacturer.add(y.get("manufacturer"))
#     director.add(y.get("director"))
#     cate.update(y["cate"])
#     nplay.update(y["play"])
#     print "#######"
# tmp = set()
# for y in db.avgirl.find():
#     result = db.img.find_one({"type":"avgirl","source":y.get("thumb")}) or {}
#     if y.get("name") not in tmp:
#         play.add((y.get("name"),y.get("key"),result.get("path"),y.get("url")))
#     tmp.add(y.get("name"))
#     print y.get("thumb")
# import ipdb;ipdb.set_trace()
# nplay = nplay - tmp
# import ipdb;ipdb.set_trace()
import MySQLdb
# db = MySQLdb.connect("127.0.0.1","root","123456789", "shantianjun",charset="utf8")
db = MySQLdb.connect("47.75.39.50","xiaolei","xiaolei", "shantianjunbak",charset="utf8")

# 使用cursor()方法获取操作游标
cursor = db.cursor()

# 使用execute方法执行SQL语句
# import ipdb;ipdb.set_trace()
sql = "insert ignore into dmm_tag (name) values (%s)"
cate = [(x,) for x in list(cate)]
cursor.executemany(sql,cate)
db.commit()
# sql = "insert into dmm_play (name,latin,thumb,url) values (%s,%s,%s,%s)"
# plays = [x for x in play]
# cursor.executemany(sql,plays)

# sql = "insert into dmm_play (name) values (%s)"
# cursor.executemany(sql,[(x,) for x in nplay])

sql = "insert ignore into dmm_manufacturer (name) values (%s)"
manufacturer = [(x,) for x in list(manufacturer)]
cursor.executemany(sql,manufacturer)
db.commit()

sql = "insert ignore into dmm_director (name) values (%s)"
director = [(x,) for x in list(director)]
cursor.executemany(sql,director)
db.commit()

sql = "insert ignore into dmm_cate (name) values (%s)"
tag = [(x,) for x in list(tag)]
cursor.executemany(sql,tag)
db.commit()

sql = "insert ignore into dmm_series (name) values (%s)"
series = [(x,) for x in list(series)]
cursor.executemany(sql,series)
db.commit()

cursor.close()
db.commit()
